
<div id="page-title"><?php echo lang('ratesheets_purchase_home_title')?></div>

<div id="page-desc"><?php echo lang('ratesheets_purchase_home_desc')?></div>

<div class="ui-widget"> 
    <div id="content">
        <!-- PAGE CONTENT -->

		<form action="" method="post" enctype="multipart/form-data" id="add_file" >
		<fieldset class="ui-widget-content ui-corner-all">
			<p class="column">
				<label><?php echo lang('term_upload_xls')?>: </label><input type="file" name='upload_xls' id='xls_file' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' />
			</p>
			<p class="column">
				<label><?php echo lang('term_upload_csv')?>: </label><input type="file" name='upload_csv' id='csv_file' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' />
			</p>
			<p>
				<label for="received-date"><?php echo lang('term_date_from')?></label>
				<input type="text" name="received-date" id="received-date"/>
			</p>
               
		</fieldset>
		<br/>
		<p class='bottom' style="margin-bottom: 20px;">
			<p class="ajax-loader"><img src="<?php echo IMG_PATH . '/ajax-loader.gif'; ?>" /></p> 
			<input type='submit' id="module_csv_upload_numbers" name='data[submit_upload]' value='<?php echo lang('button_upload')?>' class='ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all' />
		</p>
		</form>
				
		<?php
		
			// display Upload process result
			if(false === $upload_error) // File is upload, OK
			{
				//Display message
				echo "<div id='response' class='ui-state-highlight ui-corner-all' style='padding: 10px;'>";
				echo "<span class='highlight-icon ui-icon ui-icon-info' ></span><span style='color:green'>$upload_success</span>";
				echo "</div>";
				
				// ok. ALL numbers in NEW, show dialog width numbers
				// Populate dialog ,then open dialog
				
				if(count($upload_data_csv['upload_csv_data']) > 0)
				{
					?>
					<div id="dialog_csv" title="<?=lang('msg_termination_data_list')?>">
						<p><?=lang('msg_termination_data_list')?> (<?php echo count($upload_data_csv['upload_csv_data']); ?>):</p>
						<ul>
							<?php

							$data = $upload_data_csv['upload_csv_data'];
							reset($data);
							
							$data1 = current($data);
							$data2 = next($data);
							$data3 = next($data);
							$data4 = next($data);
							$data5 = next($data);

							$data10 = end($data);
							$data9 = prev($data);
							$data8 = prev($data);
							$data7 = prev($data);
							$data6 = prev($data);

								if(count($data1) == 5){ echo "<li> {$data1[0]}, {$data1[1]}, {$data1[2]} , {$data1[3]}, {$data1[4]}</li>";}
								if(count($data2) == 5){ echo "<li> {$data2[0]}, {$data2[1]}, {$data2[2]}, {$data2[3]}, {$data2[4]}</li>";}
								if(count($data3) == 5){ echo "<li> {$data3[0]}, {$data3[1]}, {$data3[2]}, {$data3[3]}, {$data3[4]}</li>";}
								if(count($data4) == 5){ echo "<li> {$data4[0]}, {$data4[1]}, {$data4[2]}, {$data4[3]}, {$data4[4]}</li>";}
								if(count($data5) == 5){ echo "<li> {$data5[0]}, {$data5[1]}, {$data5[2]}, {$data5[3]}, {$data5[4]}</li>";}
								echo "<br/>...<br/>";
								if(count($data) > 9)
								{
									if(count($data6) == 5){ echo "<li> {$data6[0]}, {$data6[1]}, {$data6[2]}, {$data6[3]}, {$data6[4]}</li>";}
									if(count($data7) == 5){ echo "<li> {$data7[0]}, {$data7[1]}, {$data7[2]}, {$data7[3]}, {$data7[4]}</li>";}
									if(count($data8) == 5){ echo "<li> {$data8[0]}, {$data8[1]}, {$data8[2]}, {$data8[3]}, {$data8[4]}</li>";}
									if(count($data9) == 5){ echo "<li> {$data9[0]}, {$data9[1]}, {$data9[2]}, {$data9[3]}, {$data9[4]}</li>";}
									if(count($data10) == 5){ echo "<li> {$data10[0]}, {$data10[1]}, {$data10[2]}, {$data10[3]}, {$data10[4]}</li>";}
								}
							?>
						</ul>
					</div>
					<script>
					<?php
						
						$allData['csv'] = $data;
						$allData['xls'] = $upload_data_xls['upload_xls_name'];
						$allData['received_date'] = $received_date;
					
					?> 
					
					data = <?php print json_encode(json_encode(json_encode($allData))); // because three dimensional range ?>;

					$(function() {
						// Show dialog
						$("#dialog_csv").dialog('open');

					});
					</script>

				<?php
				} else {}
			
				
			} elseif(!empty($upload_error)) { // ERROR
				
				echo "<div id='response' class='ui-state-error ui-corner-all' style='padding: 10px;' >";
				echo "<span class='highlight-icon ui-icon ui-icon-info' ></span><span>$upload_error</span>";
				echo "</div>";
			} else {}
		
		?>
				
		<?php 
			/*  OLD CODE !!!!!!!!!!!!!
			
			// display Upload process result
			if($upload_data_csv['upload_csv']) // File is upload
			{
				//Display message
				if($upload_data_csv['upload_msg_csv'])
				{
					echo "<div id='response' class='ui-state-highlight ui-corner-all' style='padding: 10px;'>";
					echo "<span class='highlight-icon ui-icon ui-icon-info' ></span><span style='color:green'>{$upload_data_csv['upload_msg_csv']}</span>";
					echo "</div>";
				}
				// ok. ALL numbers in NEW, show dialog width numbers
				// Populate dialog ,then open dialog
				
				if(count($upload_data_csv['upload_csv_data']) > 0)
				{
					?>
					<div id="dialog_csv" title="<?=lang('msg_termination_data_list')?>">
						<p><?=lang('msg_termination_data_list')?> (<?php echo count($upload_data_csv['upload_csv_data']); ?>):</p>
						<ul>
							<?php

							$data = $upload_data_csv['upload_csv_data'];
							reset($data);
							$data1 = current($data);
							$data2 = next($data);
							$data3 = next($data);
							$data4 = next($data);
							$data5 = next($data);

							$data10 = end($data);
							$data9 = prev($data);
							$data8 = prev($data);
							$data7 = prev($data);
							$data6 = prev($data);

								if(count($data1) == 3){ echo "<li> {$data1[0]}, {$data1[1]}, {$data1[2]}</li>";}
								if(count($data2) == 3){ echo "<li> {$data2[0]}, {$data2[1]}, {$data2[2]}</li>";}
								if(count($data3) == 3){ echo "<li> {$data3[0]}, {$data3[1]}, {$data3[2]}</li>";}
								if(count($data4) == 3){ echo "<li> {$data4[0]}, {$data4[1]}, {$data4[2]}</li>";}
								if(count($data5) == 3){ echo "<li> {$data5[0]}, {$data5[1]}, {$data5[2]}</li>";}
								echo "<br/>...<br/>";
								if(count($data) > 9)
								{
									if(count($data6) == 3){ echo "<li> {$data6[0]}, {$data6[1]}, {$data6[2]}</li>";}
									if(count($data7) == 3){ echo "<li> {$data7[0]}, {$data7[1]}, {$data7[2]}</li>";}
									if(count($data8) == 3){ echo "<li> {$data8[0]}, {$data8[1]}, {$data8[2]}</li>";}
									if(count($data9) == 3){ echo "<li> {$data9[0]}, {$data9[1]}, {$data9[2]}</li>";}
									if(count($data10) == 3){ echo "<li> {$data10[0]}, {$data10[1]}, {$data10[2]}</li>";}
								}
							?>
						</ul>
					</div>
					<script>

					data = <?php print json_encode(json_encode($data)); ?>;

					$(function() {
						// Show dialog
						$("#dialog_csv").dialog('open');

					});
					</script>

				<?php
				} else {}
			}
			else // File is not CSV
			{
				if($upload_data_csv['upload_msg_csv'])
				{
					echo "<div id='response' class='ui-state-error ui-corner-all' style='padding: 10px;' >";
					echo "<span class='highlight-icon ui-icon ui-icon-info' ></span><span>{$upload_data_csv['upload_msg_csv']}</span>";
					echo "</div>";
				}
			}
		?>
			<?php
			if($upload_data_xls['upload_xls']) // File is upload
			{
				//Display message
				if($upload_data_xls['upload_msg_xls'])
				{
					echo "<div id='response' class='ui-state-highlight ui-corner-all' style='padding: 10px;'>";
					echo "<span class='highlight-icon ui-icon ui-icon-info' ></span><span style='color:green'>{$upload_data_xls['upload_msg_xls']}</span>";
					echo "</div>";
				}
			}
			else // File is not XLS
			{
				if($upload_data_xls['upload_msg_xls'])
				{
					echo "<div id='response' class='ui-state-error ui-corner-all' style='padding: 10px;' >";
					echo "<span class='highlight-icon ui-icon ui-icon-info' ></span><span>{$upload_data_xls['upload_msg_xls']}</span>";
					echo "</div>";
				}
			}
			 
			*/
		?>
		<div id="response" style="padding: 10px;"></div> 
    <div style="padding: 10px;" id='response_insert'"></div>